﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ATW.MT.CommonClass;
using ATW.MT.BUS;
using System.Data;
using System.Text;

namespace ATW.MT.SellManage
{
    public partial class SpecificationManage : CommonPage
    {
        bus_C_Material dm = new bus_C_Material();
        bus_C_Size cs = new bus_C_Size();
        bus_C_Pressure cp = new bus_C_Pressure();
        bus_C_Conn cc = new bus_C_Conn();
        bus_C_Design cd = new bus_C_Design();
        bus_C_FranLevel cf = new bus_C_FranLevel();
        bus_C_StructLevel SL = new bus_C_StructLevel();
        bus_C_SealLevel Se = new bus_C_SealLevel();
        bus_C_Temp CT = new bus_C_Temp();
        bus_D_SystemArgs ds = new bus_D_SystemArgs();
        private decimal _rateMax = 1;
        private decimal _rateMin = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentPage"] == null)
                {
                    Session["CurrentPage"] = "Material";
                }
                BindData();
            }
        }
        private void BindData()
        {//根据类型加载对应参数管理页面
            _rateMax =decimal.Parse(ds.GetSysArgs("MaxRate"));
            _rateMin = decimal.Parse(ds.GetSysArgs("MinRate"));
            #region 材质
            if (Session["CurrentPage"].ToString() == "Material")
            {
                divMaterial.Style["display"] = "block";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name_m = txtMaterialName.Value.Trim();
                if (!common.filterChar(name_m))
                {
                    Tips("查询参数不合法！");
                    return;
                }
                DataTable dt = dm.MaterialPagerQuery(name_m, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                    Tips("没有检索到相关数据");
                }
                rpListM.DataSource = dt;
                rpListM.DataBind();
            }
            #endregion
            #region 口径
            if (Session["CurrentPage"].ToString() == "Size")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "block";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtSize.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询条件中含有非法字符！");
                    return;
                }
                DataTable dt = cs.SizePagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 1;
                }
                rpListS.DataSource = dt;
                rpListS.DataBind();
            }
            #endregion
            #region 压力等级
            if (Session["CurrentPage"].ToString() == "Pressure")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "block";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtPressure.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询条件中含有非法字符！");
                    return;
                }
                DataTable dt = cp.PressPagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListP.DataSource = dt;
                rpListP.DataBind();
            }

            #endregion
            #region 设计标准
            if (Session["CurrentPage"].ToString() == "Design")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "block";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtDesign.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询参数中存在非法字符！");
                    return;
                }
                DataTable dt = cd.DesignPagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListDesign.DataSource = dt;
                rpListDesign.DataBind();
            }
            #endregion
            #region 连接方式
            if (Session["CurrentPage"].ToString() == "Conn")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "block";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtConn.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询条件含有非法字符！");
                    return;
                }
                DataTable dt = cc.ConnPagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListC.DataSource = dt;
                rpListC.DataBind();
            }
            #endregion
            #region 法兰标准
            if (Session["CurrentPage"].ToString() == "Fran")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "block";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtFran.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询条件中存在危险字符！");
                    return;
                }
                DataTable dt = cf.FranPagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListFran.DataSource = dt;
                rpListFran.DataBind();
            }
            #endregion
            #region 结构标准
            if (Session["CurrentPage"].ToString() == "Struct")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "block";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "none";

                string name = txtStruct.Value.Trim();
                if (!common.filterChar(name))
                {
                    Tips("查询条件当中存在危险字符！");
                    return;
                }
                DataTable dt = SL.StructPagerQuery(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
      
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListStruct.DataSource = dt;
                rpListStruct.DataBind();
            }
            #endregion
            #region 密封等级
            if (Session["CurrentPage"].ToString() == "Seal")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "block";
                divTemp.Style["display"] = "none";

                string type = txtSeal.Value.Trim();
                if (!common.filterChar(type))
                {
                    Tips("查询条件中含有危险字符！");
                    return;
                }
                DataTable dt = Se.SealPagerQuery(type, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpListSeal.DataSource = dt;
                rpListSeal.DataBind();
            }
            #endregion
            #region 温度
            if (Session["CurrentPage"].ToString() == "Temp")
            {
                divMaterial.Style["display"] = "none";
                divSize.Style["display"] = "none";
                divConn.Style["display"] = "none";
                divDesign.Style["display"] = "none";
                divPressure.Style["display"] = "none";
                divFran.Style["display"] = "none";
                divStruct.Style["display"] = "none";
                divSeal.Style["display"] = "none";
                divTemp.Style["display"] = "block";

                string desc = txtTemp.Value.Trim();
                if (!common.filterChar(desc))
                {
                    Tips("查询参数中存在非法字符！");
                    return;
                }
                try
                {
                    DataTable dt = CT.TempPagerQuery(desc, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                    }
                    else
                    {
                        AspNetPager1.RecordCount = 0;
                    }
                    rpTemp.DataSource = dt;
                    rpTemp.DataBind();
                }
                catch (Exception ex)
                {
                }

            }
            #endregion
        }

        #region 材质
        protected void btnMaterial_Click(object sender, EventArgs e)
        {
            Session["CurrentPage"] = "Material";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddM_Click(object sender, EventArgs e)
        {//点击新增按钮
            if (!liAddMt.Visible)
            {
                liAddMt.Visible = true;
                txtAddCodeD.Text = "";
                txtAddCodeZ.Text = "";
                txtMaterialRate.Text = "";
            }
        }
        protected void lbnSaveNewMaterial_Click(object sender, EventArgs e)
        {//保存新增
            string code_d = txtAddCodeD.Text.Trim();
            string code_z = txtAddCodeZ.Text.Trim();
            string rate = txtMaterialRate.Text.Trim();
            if (code_z == "无")
            {
                code_z = "";
            }
            try
            {
                if (code_d == "")
                {
                    Tips("请输入锻件编号！");
                    return;
                }
                if (!common.filterChar(code_d) || !common.filterChar(code_z))
                {
                    Tips("输入参数中含有危险字符！");
                    return;
                }
                if (dm.IsMaterialExist(code_d))
                {
                    Tips("该材质已经存在！");
                    return;
                }
                decimal _rate = 0;
                if (!decimal.TryParse(rate, out _rate) || _rate <= 0)
                {
                    Tips("材质价格系数应当大于0");
                    return;
                }
                int result = dm.MaterialAdd(code_d, code_z, rate);
                if (result > 0)
                {
                    Tips("新增成功！");
                    BindData();
                    txtAddCodeD.Text = "";
                    txtAddCodeZ.Text = "";
                    txtMaterialRate.Text = "";
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        protected void lbnEditMaterial_Click(object sender, EventArgs e)
        {//点击编辑
            LinkButton lbn = (LinkButton)sender;
            TextBox txtCode_d = (TextBox)lbn.Parent.FindControl("txtCode");
            Label lblCode_d = (Label)lbn.Parent.FindControl("lblCode");
            TextBox txtCode_z = (TextBox)lbn.Parent.FindControl("txtCode_Z");
            Label lblCode_z = (Label)lbn.Parent.FindControl("lblCode_Z");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            Label lblRate = (Label)lbn.Parent.FindControl("lblRate");
            LinkButton btnSave = (LinkButton)lbn.Parent.FindControl("lbnSaveMaterial");
            if (txtCode_d != null && txtCode_z != null && lblCode_d != null && lblCode_z != null && btnSave != null)
            {
                txtCode_d.Visible = true;
                lblCode_d.Visible = false;
                txtCode_z.Visible = true;
                lblCode_z.Visible = false;
                lblRate.Visible = false;
                txtRate.Visible = true;
                lbn.Visible = false;
                btnSave.Visible = true;
                txtCode_z.Text = lblCode_z.Text;
                txtCode_d.Text = lblCode_d.Text;
                txtRate.Text = lblRate.Text;
            }
        }
        protected void lbnSaveMaterial_Click(object sender, EventArgs e)
        {//保存编辑
            LinkButton lbn = (LinkButton)sender;
            string mid = lbn.CommandArgument;
            TextBox txtCode_d = (TextBox)lbn.Parent.FindControl("txtCode");
            TextBox txtCode_z = (TextBox)lbn.Parent.FindControl("txtCode_Z");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            string code_d = txtCode_d.Text.Trim();
            string code_z = txtCode_z.Text.Trim();
            string rate = txtRate.Text.Trim();
            if (code_z == "无")
            {
                code_z = "";
            }
            try
            {
                if (code_d == "")
                {
                    Tips("锻件名称不能为空！");
                    return;
                }
                if (!common.filterChar(code_d) || !common.filterChar(code_z))
                {
                    Tips("输入参数中存在危险字符！");
                    return;
                }
                if (rate == "")
                {
                    Tips("价格系数不能为空！");
                    return;
                }
                decimal _rate = 0;
                if (!decimal.TryParse(rate, out _rate) || _rate <= 0)
                {
                    Tips("价格系数应当为整数或小数！");
                    return;
                }
                if (_rate > _rateMax || _rate < _rateMin)
                {
                    Tips("价格系数超出可调范围限制！");
                    return;
                }
                int result = dm.MaterialEdit(code_d, code_z, rate, mid);
                if (result > 0)
                {
                    Tips("修改成功！");
                    BindData();
                }
                else
                {
                    Tips("修改失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 口径
        protected void btnSize_Click(object sender, EventArgs e)
        {
            Session["CurrentPage"] = "Size";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnSizeSaveEdit_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            TextBox txtCode_C = (TextBox)lbn.Parent.FindControl("txtCode_C");
            TextBox txtCode_S = (TextBox)lbn.Parent.FindControl("txtCode_S");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfSid");
            if (txtCode_C != null && txtCode_S != null & hdf != null)
            {
                string code_c = txtCode_C.Text.Trim();
                string code_s = txtCode_S.Text.Trim();
                string rate = txtRate.Text;
                string sid = hdf.Value;
                decimal _rate = 0;
                try
                {
                    if (code_c == "" || code_s == "")
                    {
                        Tips("请完整填写公制以及ANSI制的口径参数");
                        return;
                    }
                    if (!common.filterChar(code_c) || !common.filterChar(code_s))
                    {
                        Tips("口径参数中存在非法字符！");
                        return;
                    }
                    if (rate == "")
                    {
                        Tips("请填写口径价格系数！");
                        return;
                    }
                    if (!decimal.TryParse(rate, out _rate) || _rate < 0)
                    {
                        Tips("口径价格系数应当为整数或小数！");
                        return;
                    }
                    if (_rate > _rateMax || _rate < _rateMin)
                    {
                        Tips("价格系数超过可调范围限制！");
                        return;
                    }
                    int result = cs.SizeEdit(code_c, code_s, rate, sid);
                    if (result > 0)
                    {
                        Tips("修改成功！");
                        BindData();
                    }
                    else
                    {
                        Tips("修改失败！");
                        return;
                    }
                }
                catch (Exception ex)
                {

                }
            }

        }
        protected void btnSizeEdit_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            LinkButton btnSave = (LinkButton)lbn.Parent.FindControl("btnSizeSaveEdit");
            Label lblCode_C = (Label)lbn.Parent.FindControl("lblCode_C");
            TextBox txtCode_C = (TextBox)lbn.Parent.FindControl("txtCode_C");
            Label lblCode_S = (Label)lbn.Parent.FindControl("lblCode_S");
            TextBox txtCode_S = (TextBox)lbn.Parent.FindControl("txtCode_S");
            Label lblRate = (Label)lbn.Parent.FindControl("lblRate");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            if (btnSave != null && lblCode_C != null && txtCode_C != null && lblCode_S != null && txtCode_S != null)
            {
                lbn.Visible = false;
                btnSave.Visible = true;
                lblCode_C.Visible = false;
                lblCode_S.Visible = false;
                txtCode_C.Visible = true;
                txtCode_S.Visible = true;
                txtRate.Visible = true;
                lblRate.Visible = false;
                txtRate.Text = lblRate.Text;
                txtCode_C.Text = lblCode_C.Text;
                txtCode_S.Text = lblCode_S.Text;
            }
        }
        protected void lbnAddSize_Click(object sender, EventArgs e)
        {
            string url = "_addSize.aspx?r=" + new Random().Next(1000).ToString();
            OpenDialog("新增口径", url, "height=300,width=400");
        }
        #endregion

        #region 压力等级
        protected void btnPressure_Click(object sender, EventArgs e)
        {
            Session["CurrentPage"] = "Pressure";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void lbnAddPressure_Click(object sender, EventArgs e)
        {
            string url = "_addPressure.aspx?r=" + new Random().Next(1000).ToString();
            OpenDialog("新增压力等级", url, "height=300,width=400");
        }
        protected void btnPressureEdit_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            LinkButton btnSave = (LinkButton)lbn.Parent.FindControl("btnPressureSaveEdit");
            Label lblCode_C = (Label)lbn.Parent.FindControl("lblCode_C");
            TextBox txtCode_C = (TextBox)lbn.Parent.FindControl("txtCode_C");
            Label lblCode_S = (Label)lbn.Parent.FindControl("lblCode_S");
            TextBox txtCode_S = (TextBox)lbn.Parent.FindControl("txtCode_S");
            Label lblRate = (Label)lbn.Parent.FindControl("lblRate");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            if (btnSave != null && lblCode_C != null && txtCode_C != null && lblCode_S != null && txtCode_S != null)
            {
                lbn.Visible = false;
                btnSave.Visible = true;
                lblCode_C.Visible = false;
                lblCode_S.Visible = false;
                txtCode_C.Visible = true;
                txtCode_S.Visible = true;
                lblRate.Visible = false;
                txtRate.Visible = true;

                txtCode_C.Text = lblCode_C.Text;
                txtCode_S.Text = lblCode_S.Text;
                txtRate.Text = lblRate.Text;
            }
        }
        protected void btnPressureSaveEdit_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            TextBox txtCode_C = (TextBox)lbn.Parent.FindControl("txtCode_C");
            TextBox txtCode_S = (TextBox)lbn.Parent.FindControl("txtCode_S");
            TextBox txtRate = (TextBox)lbn.Parent.FindControl("txtRate");
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfPid");
            if (txtCode_C != null && txtCode_S != null & hdf != null)
            {
                string code_c = txtCode_C.Text.Trim();
                string code_s = txtCode_S.Text.Trim();
                string rate = txtRate.Text;
                string pid = hdf.Value;
                decimal _rate = 0;
                try
                {
                    if (code_c == "" || code_s == "")
                    {
                        Tips("请完整填写公制以及ANSI制的压力等级参数");
                        return;
                    }
                    if (rate == "")
                    {
                        Tips("请填写价格系数！");
                        return;
                    }
                    if (!common.filterChar(code_c) || !common.filterChar(code_s))
                    {
                        Tips("压力等级参数中存在非法字符！");
                        return;
                    }
                    if (!decimal.TryParse(rate, out _rate) || _rate <= 0)
                    {
                        Tips("价格系数应当为整数或者小数！");
                        return;
                    }
                    if (_rate > _rateMax || _rate < _rateMin)
                    {
                        Tips("价格系数超过可调范围限制！");
                        return;
                    }
                    int result = cp.PressureEdit(code_c, code_s, rate, pid);
                    if (result > 0)
                    {
                        Tips("修改成功！");
                        BindData();
                    }
                    else
                    {
                        Tips("修改失败！");
                        return;
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
        #endregion

        #region 设计标准
        protected void btnDesign_Click(object sender, EventArgs e)
        {
            Session["CurrentPage"] = "Design";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void lbnAddDesign_Click(object sender, EventArgs e)
        {//新增按钮
            if (!liAdd.Visible)
            {
                liAdd.Visible = true;
                txtAddDesign.Text = "";
            }
        }
        protected void btnDesignEdit_Click(object sender, EventArgs e)
        {//编辑按钮
            LinkButton lbn = (LinkButton)sender;
            LinkButton lbnSave = (LinkButton)lbn.Parent.FindControl("btnDesignSaveEdit");
            Label lbl = (Label)lbn.Parent.FindControl("lblCode");
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtCode");
            if (lbnSave != null && lbl != null && txt != null)
            {
                lbn.Visible = false;
                lbnSave.Visible = true;
                lbl.Visible = false;
                txt.Visible = true;
                txt.Text = lbl.Text;
            }
        }
        protected void btnDesignSaveEdit_Click(object sender, EventArgs e)
        {//保存修改
            LinkButton lbn = (LinkButton)sender;
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtCode");
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfPid");
            if (txt != null && hdf != null)
            {
                string desc = txt.Text.Trim();
                string did = hdf.Value;
                try
                {
                    if (desc == "")
                    {
                        Tips("设计标准名称不能为空！");
                        return;
                    }
                    if (!common.filterChar(desc))
                    {
                        Tips("设计标准名称中含有危险字符！");
                        return;
                    }
                    int result = cd.DesignEdit(desc, did);
                    if (result > 0)
                    {
                        Tips("修改成功！");
                        BindData();
                    }
                    else
                    {
                        Tips("修改失败！");
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
        protected void SaveNewDesign_Click(object sender, EventArgs e)
        {//保存新增
            string desc = txtAddDesign.Text.Trim();
            try
            {
                if (desc == "")
                {
                    Tips("设计标准名称不能为空！");
                    return;
                }
                if (!common.filterChar(desc))
                {
                    Tips("设计标准名称中存在非法字符！");
                    return;
                }
                if (cd.isDesignExist(desc))
                {
                    Tips("该设计标准已经存在！");
                    return;
                }
                int result = cd.DesignAdd(desc);
                if (result > 0)
                {
                    Tips("新增设计标准成功！");
                    BindData();
                    txtAddDesign.Text = "";
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 连接方式
        protected void btnConn_Click(object sender, EventArgs e)
        {//连接方式
            Session["CurrentPage"] = "Conn";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddC_Click(object sender, EventArgs e)
        {//新增连接方式
            string url = "_addConn.aspx?r=" + new Random().Next(1000).ToString();
            OpenDialog("新增连接方式", url, "height=300,width=400");
        }
        protected void lbnEditConnDesc_Click(object sender, EventArgs e)
        {//修改描述
            LinkButton lbn = (LinkButton)sender;
            Label lblDesc = (Label)lbn.Parent.FindControl("lblDesc");
            TextBox txtDesc = (TextBox)lbn.Parent.FindControl("txtDesc");
            Label lblCode = (Label)lbn.Parent.FindControl("lbnCode");
            TextBox txtCode = (TextBox)lbn.Parent.FindControl("txtCode");
            LinkButton lbnSave = (LinkButton)lbn.Parent.FindControl("lbnSaveConnDesc");
            if (lblDesc != null && lblCode != null && txtDesc != null && txtCode != null)
            {
                lblCode.Visible = false;
                lblDesc.Visible = false;
                txtCode.Visible = true;
                txtDesc.Visible = true;
                txtDesc.Text = lblDesc.Text;
                txtCode.Text = lblCode.Text;
                lbnSave.Visible = true;
                lbn.Visible = false;
            }
        }
        protected void lbnSaveConnDesc_Click(object sender, EventArgs e)
        {//保存修改
            LinkButton lbn = (LinkButton)sender;
            TextBox txtDesc = (TextBox)lbn.Parent.FindControl("txtDesc");
            TextBox txtCode = (TextBox)lbn.Parent.FindControl("txtCode");
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfCid");
            try
            {
                string desc = txtDesc.Text.Trim();
                string code = txtCode.Text.Trim();
                if (desc == "")
                {
                    Tips("请填写连接方式！");
                    return;
                }
                if (code == "")
                {
                    Tips("请填写连接方式缩写！");
                    return;
                }
                if (!common.filterChar(desc) || !common.filterChar(code))
                {
                    Tips("填写内容中含有非法字符！");
                    return;
                }
                if (cc.ConnDescEdit(hdf.Value, desc, code))
                {
                    Tips("修改成功！");
                    BindData();
                }
                else
                {
                    Tips("修改失败！");
                }
            }
            catch (Exception ex)
            {

            }

        }
        #endregion

        #region 法兰标准
        protected void btnFran_Click(object sender, EventArgs e)
        {//法兰标准
            Session["CurrentPage"] = "Fran";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddF_Click(object sender, EventArgs e)
        {//新增标准
            if (!liAddF.Visible)
            {
                liAddF.Visible = true;
                txtAddFran.Text = "";
            }
        }
        protected void lbnEditFranDesc_Click(object sender, EventArgs e)
        {//编辑
            LinkButton lbn = (LinkButton)sender;
            Label lbl = (Label)lbn.Parent.FindControl("lblDesc");
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtDesc");
            LinkButton lbnSave = (LinkButton)lbn.Parent.FindControl("lbnSaveFranDesc");
            if (lbl != null && txt != null && lbnSave != null)
            {
                lbn.Visible = false;
                lbl.Visible = false;
                txt.Visible = true;
                lbnSave.Visible = true;
                txt.Text = lbl.Text;
            }
        }
        protected void lbnSaveFranDesc_Click(object sender, EventArgs e)
        {//保存修改
            LinkButton lbn = (LinkButton)sender;
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfFid");
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtDesc");
            if (hdf != null && txt != null)
            {
                string desc = txt.Text.Trim();
                string fid = hdf.Value;
                try
                {
                    if (desc == "")
                    {
                        Tips("标准名称不能为空！");
                        return;
                    }
                    if (!common.filterChar(desc))
                    {
                        Tips("标准名称当中存在非法字符！");
                        return;
                    }
                    int result = cf.FranEdit(desc, fid);
                    if (result > 0)
                    {
                        Tips("修改成功！");
                        BindData();
                    }
                    else
                    {
                        Tips("修改失败！");
                    }
                }
                catch (Exception ex)
                {

                }

            }
        }
        protected void SaveNewFran_Click(object sender, EventArgs e)
        {
            string desc = txtAddFran.Text.Trim();
            try
            {
                if (desc == "")
                {
                    Tips("标准名称不能为空！");
                    return;
                }
                if (!common.filterChar(desc))
                {
                    Tips("标准名称中含有危险字符！");
                    return;
                }
                if (cf.isFranExist(desc))
                {
                    Tips("该法兰标准已经存在！");
                    return;
                }
                int result = cf.FranAdd(desc);
                if (result > 0)
                {
                    Tips("新增成功！");
                    BindData();
                    txtAddFran.Text = "";
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 结构标准
        protected void btnStruct_Click(object sender, EventArgs e)
        {//结构标准
            Session["CurrentPage"] = "Struct";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddS_Click(object sender, EventArgs e)
        {//新增标准
            if (!liAddStruct.Visible)
            {
                liAddStruct.Visible = true;
                txtStructAdd.Text = "";
            }
        }
        protected void SaveNewStruct_Click(object sender, EventArgs e)
        {//新增
            string desc = txtStructAdd.Text.Trim();
            try
            {
                if (desc == "")
                {
                    Tips("标准名称不能为空！");
                    return;
                }
                if (!common.filterChar(desc))
                {
                    Tips("标准名称中含有危险字符！");
                    return;
                }
                if (SL.isStructExist(desc))
                {
                    Tips("该结构标准已经存在！");
                    return;
                }
                int result = SL.StructAdd(desc);
                if (result > 0)
                {
                    Tips("新增成功！");
                    BindData();
                    txtStructAdd.Text = "";
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        protected void lbnEditStructDesc_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            Label lbl = (Label)lbn.Parent.FindControl("lblDesc");
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtDesc");
            LinkButton lbnSave = (LinkButton)lbn.Parent.FindControl("lbnSaveStructDesc");
            if (lbl != null && txt != null && lbnSave != null)
            {
                lbn.Visible = false;
                lbl.Visible = false;
                txt.Visible = true;
                lbnSave.Visible = true;
                txt.Text = lbl.Text;
            }
        }
        protected void lbnSaveStructDesc_Click(object sender, EventArgs e)
        {//新增
            LinkButton lbn = (LinkButton)sender;
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfFid");
            TextBox txt = (TextBox)lbn.Parent.FindControl("txtDesc");
            if (hdf != null && txt != null)
            {
                string sid = hdf.Value;
                string desc = txt.Text.Trim();
                try
                {
                    if (desc == "")
                    {
                        Tips("标准名称不能为空！");
                        return;
                    }
                    if (!common.filterChar(desc))
                    {
                        Tips("标准名称当中存在非法字符！");
                        return;
                    }
                    int result = SL.StructEdit(desc, sid);
                    if (result > 0)
                    {
                        Tips("修改成功！");
                        BindData();
                    }
                    else
                    {
                        Tips("修改失败！");
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
        #endregion

        #region 密封等级
        protected void btnSeal_Click(object sender, EventArgs e)
        {//密封等级
            Session["CurrentPage"] = "Seal";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddSeal_Click(object sender, EventArgs e)
        {//新增按钮
            if (!liSeal.Visible)
            {
                liSeal.Visible = true;
                txtSealAdd.Text = "";
                txtSealCodeAdd.Text = "";
            }
        }
        protected void SaveNewSeal_Click(object sender, EventArgs e)
        {//保存新增
            string type = txtSealAdd.Text.Trim();
            string level = txtSealCodeAdd.Text.Trim();
            try
            {
                if (type == "")
                {
                    Tips("密封标准不能为空！");
                    return;
                }
                if (level == "")
                {
                    level = "无等级区分";
                }
                if (!common.filterChar(type) || !common.filterChar(level))
                {
                    Tips("填写参数中含有危险字符！");
                    return;
                }
                if (Se.isSealExist(type, level))
                {
                    Tips("该密封等级已经存在！");
                    return;
                }
                int result = Se.SealAdd(type, level);
                if (result > 0)
                {
                    Tips("新增成功！");
                    BindData();
                    txtSealAdd.Text = "";
                    txtSealCodeAdd.Text = "";
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        protected void lbnEditSealDesc_Click(object sender, EventArgs e)
        {//编辑按钮
            LinkButton lbn = (LinkButton)sender;
            TextBox txtType = (TextBox)lbn.Parent.FindControl("txtType");
            Label lblType = (Label)lbn.Parent.FindControl("lblType");
            TextBox txtLevel = (TextBox)lbn.Parent.FindControl("txtLevel");
            Label lblLevel = (Label)lbn.Parent.FindControl("lblLevel");
            LinkButton lbnSave = (LinkButton)lbn.Parent.FindControl("lbnSaveSealDesc");
            if (txtType != null && lblType != null && txtLevel != null && lblLevel != null && lbnSave != null)
            {
                lbn.Visible = false;
                txtType.Visible = true;
                lblType.Visible = false;
                txtLevel.Visible = true;
                lblLevel.Visible = false;
                lbnSave.Visible = true;
                txtType.Text = lblType.Text;
                txtLevel.Text = lblLevel.Text;
            }
        }
        protected void lbnSaveSealDesc_Click(object sender, EventArgs e)
        {//保存编辑
            LinkButton lbn = (LinkButton)sender;
            TextBox txtType = (TextBox)lbn.Parent.FindControl("txtType");
            TextBox txtLevel = (TextBox)lbn.Parent.FindControl("txtLevel");
            HiddenField hdf = (HiddenField)lbn.Parent.FindControl("hdfFid");
            if (txtType != null && txtLevel != null && hdf != null)
            {
                string type = txtType.Text.Trim();
                string level = txtLevel.Text.Trim();
                if (type == "")
                {
                    Tips("密封标准不能为空！");
                    return;
                }
                if (level == "")
                {
                    level = "无等级区分";
                    return;
                }
                if (!common.filterChar(type) || !common.filterChar(level))
                {
                    Tips("填写参数中存在非法字符！");
                    return;
                }
                int result = Se.SealEdit(type, level, hdf.Value);
                if (result > 0)
                {
                    Tips("修改成功！");
                    BindData();
                }
                else
                {
                    Tips("修改失败！");
                }
            }
        }
        #endregion

        #region 温度
        protected void btnTemp_Click(object sender, EventArgs e)
        {
            Session["CurrentPage"] = "Temp";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void btnAddTemp_Click(object sender, EventArgs e)
        {//新增温度
            string url = "../SellManage/_addTemp.aspx?r=" + new Random().Next(1000);
            OpenDialog("新增温度区间", url, "height=300,width=400");
        }
        protected void lbnEditTemp_Click(object sender, EventArgs e)
        {//修改温度
            LinkButton lbn = (LinkButton)sender;
            string pid = lbn.CommandArgument;
            string url = "../SellManage/_addTemp.aspx?pid=" + pid + "&r=" + new Random().Next(1000);
            OpenDialog("修改温度区间", url, "height=300,width=400");
        }
        #endregion
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        private void Tips(string s)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }//提示
    }
}